import { SvgComponent } from "@/components/base/Svg"
import ButtonRegular from "@/components/composite/ButtonRegular/main"
import styled from "@emotion/styled"
import { ChangeEvent } from "react"

const Container = styled.div`
    font-family: "Gilroy", sans-serif;
    padding: 0 4rem 0 12rem;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    height: 36rem;
    border-radius: 8rem;
    border: 1rem solid #d5d5d8;
    margin: 0 12rem;
    background-color: #fff;
    input {
        flex: 1;
        border: 0 none;
        font-family: Gilroy;
        font-weight: 500;
        font-size: 14rem;
        height: 20rem;
        line-height: 20rem;
        outline: 0 none;
        margin: 0;
        padding: 0;
        padding-left: 8rem;
    }
    button:hover {
        box-shadow: none;
    }
`

const SearchButton = styled(ButtonRegular)`
    height: 28rem;
    width: 64rem;
    font-family: "Gilroy", sans-serif;
    font-weight: 500;
    font-size: 14rem;
    line-height: 20rem;
    letter-spacing: 0;
    text-align: center;
    outline: none;
    border: none;
    box-shadow: none;
    margin-left: 12rem;
`

const Close = styled.span`
    width: 20rem;
    height: 20rem;
    display: flex;
    justify-content: center;
    align-items: center;
`
const IconCloseSvg = styled(SvgComponent("pages/HomePage/icon_close.svg"))``
const IconSearchSvg = styled(SvgComponent("pages/HomePage/icon_search.svg"))``

interface Props {
    val: string
    setVal: (val: string) => void
}
export function CategoryGameSearch({ val = "", setVal }: Props) {
    return (
        <Container>
            <IconSearchSvg />
            <input
                value={val}
                onChange={(e: ChangeEvent<HTMLInputElement>) => {
                    setVal(e.target.value)
                }}
                maxLength={50}
                placeholder="Search game name"
            />
            {val && (
                <Close
                    onClick={() => {
                        setVal("")

                    }}
                >
                    <IconCloseSvg />
                </Close>
            )}
            {/* <SearchButton
                onClick={() => {
                    if (text) {
                        setVal(text)
                    }
                }}
            >
                Search
            </SearchButton> */}
        </Container>
    )
}
